﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using TugasAkhir.Helpers;
using TugasAkhir.Objects;

namespace TugasAkhir.Models
{
    public static class DosenModel
    {
        public static bool GetDosenDetail(string nip, out DosenObject dosen)
        {
            var hasilQuery = new DataSet();
            string query = String.Format("SELECT * FROM [dbo].[dosen] WHERE [NIP] = '{0}'", nip);
            bool flag = SqlServer.ExecuteReader(query, out hasilQuery);

            if (flag)
            {
                if (hasilQuery.Tables[0] != null && hasilQuery.Tables[0].Rows.Count > 0)
                {
                    dosen = new DosenObject();
                    dosen.IdDosen = hasilQuery.Tables[0].Rows[0][0].ToString();
                    dosen.Nip = hasilQuery.Tables[0].Rows[0][2].ToString();
                    dosen.NamaDosen = hasilQuery.Tables[0].Rows[0][1].ToString();
                    dosen.GelarS1 = hasilQuery.Tables[0].Rows[0][3].ToString();
                    dosen.GelarS2 = hasilQuery.Tables[0].Rows[0][4].ToString();
                    dosen.GelarS3 = hasilQuery.Tables[0].Rows[0][5].ToString();
                    dosen.GelarProfesor = hasilQuery.Tables[0].Rows[0][6].ToString();

                    return true;
                }
                else
                {
                    dosen = new DosenObject();
                    return false;
                }
            }
            else
            {
                dosen = new DosenObject();
                return false;
            }
        } 
    } 
}